import axios from 'axios'
export default {
  namespaced: true,
  state: {
    alldata: {} // {分类id:新闻数据}
  },
  mutations: {
    // 定义更新头条内容的mutations
    updList (state, { currentCategory, list }) {
      state.alldata = { ...state.alldata, currentCategory: list }
    }
  },
  actions: {
    // 获取新闻列表数据
    // 分类id只能通过传递的方式传进来
    // 根据分类标识Id 获取新闻内容
    async getNewList (context, cateId) {
      const { data: { data: { results } } } = await axios.get(`http://toutiao-app.itheima.net/v1_1/articles?channel_id=${cateId}&timestamp=${Date.now()}&with_top=1`)
      // console.log(results);
      context.commit('updList', {
        currentCategory: cateId, list: results
      })
    }
  }
}
